Page({

  /**
   * 页面的初始数据
   */
  data: {
    btn_disabled:true,
    current:'',
    urls:'',
    isAll:false,
    select_all: false,
    m: 1000,
    d: '',
    total:'',
    pd:true,
    listData:[
      {"code":"01","name":"阿迪","price":"￥800",  "fengxiao":300,"distributionratio":"30%"},
      {"code":"02","name":"阿迪","price":"￥800",  "fengxiao":100,"distributionratio":"30%"},
      {"code":"03","name":"阿迪","price":"￥800",  "fengxiao":400,"distributionratio":"30%"},
      {"code":"04","name":"阿迪","price":"￥800","fengxiao":"300","distributionratio":"30%"},
      {"code":"05","name":"阿迪","price":"￥800","fengxiao":"300","distributionratio":"30%"},
      {"code":"06","name":"阿迪","price":"￥800","fengxiao":"300","distributionratio":"30%"},
      {"code":"07","name":"阿迪","price":"￥800","fengxiao":"300","distributionratio":"30%"}
      ]
  },
  // 单选
  checkboxChange: function (e) {
   
    var index=e.currentTarget.dataset.index
    let GWC=this.data.listData
    const checked=GWC[index].checked
    GWC[index].checked=!GWC[index].checked
    this.getTotal();
  },
  // 计算任务已完成 和 待完成 
  getTotal:function(){
    let GWC=this.data.listData
    let s=0
     for(var i=0;i<GWC.length;i++)
     {
        if(GWC[i].checked)
        {
         s+=parseFloat(GWC[i].fengxiao)
         
        }
        else
        this.setData({
          pd: false
        })
        
      }
     
        this.setData({
          total:  parseFloat(s)
        })
        this.setData({
          d:parseFloat(parseFloat(this.data.m)-this.data.total)
        })
         if(this.data.total==0)
         this.setData({
           d:0
         })

  },
 
  selectall: function () { //全选与反全选
    var that = this;
    for (let i = 0; i < that.data.listData.length; i++) {
      that.data.listData[i].checked = (!that.data.select_all)
    }
    if(that.data.select_all==false)
      that.setData({
        d: 0
      })
    that.setData({
      listData: that.data.listData,
      select_all: !that.data.select_all
    })
    this.getTotal()
    
  },
// 提交表单
submit:function(){
  wx.request({
    url: 'url地址',
    method: 'POST',
    data: {},
    header: {
      'content-type': 'application/x-www-form-urlencoded',
    },
    success: function (res) {
      console.log(res);
      console.log(res.data.data);
      that.setData({
        checkboxItems:res.data.data
      });
    }
  })

},
//预览图片
topic_preview: function(e){
  var that = this;
  wx.previewImage({
  current: url, // 当前显示图片的http链接
  urls: previewImgArr // 需要预览的图片http链接列表
  })
  },
  // 协议与提交按钮联动
  bindAgreeChange:function(e) {
    //  console.log(e.detail.value)
      this.setData({
        isAgree:e.detail.value.length,
      })
      if (e.detail.value.length==1){
       this.setData({
         btn_disabled:false,
       })
     }else{
        //onsole.log(e.detail.value.length)
       this.setData({
         btn_disabled:true
       })
     }
    },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})
